const app = getApp()

Page({
  data: {
    orderList:[],
    lo:'https://xiaochengxu.printeasy.top',
    currentTap: 0,
    nvabarData: {
      showCapsule: 0, //是否显示左上角图标   1表示显示    0表示不显示
      title: '我的订单', //导航栏 中间的标题
    },
    height: app.globalData.height * 2 + 20,
  },
  onLoad() {
     // 获取用户信息
     wx.getSetting({
      success: res => {
        if (res.authSetting['scope.userInfo']) {
        } else {
          // 未授权，跳转到授权页面
          wx.showModal({
           title:'请登录',
           icon:'none',
            success:function(){
              wx.reLaunch({
                url: '/pages/login/login',
              })
            }
          })
         
        }
      }
    })
    let url = app.globalData.URL+'goods/commodity/order/user/list/0';
        let data = {};
        let that = this;
        app.wxRequest('GET', url, data, (res) => {
          let orderList = res.rows
          that.setData({
            orderList:orderList
          })
          console.log(orderList)
        }, (err) => {
          console.log(err.errMsg)
        })
  },
  order_status: function (e) {
    var current = e.currentTarget.dataset.current
    console.log(current)
    this.setData({
      currentTap: current
    })
    let url = app.globalData.URL+'goods/commodity/order/user/list/'+current;
        let data = {};
        let that = this;
        app.wxRequest('GET', url, data, (res) => {
          let orderList = res.rows
          that.setData({
            orderList:orderList
          })
          console.log(orderList)
        }, (err) => {
          console.log(err.errMsg)
        })
  },
  goapply_sale: function(){
    wx.navigateTo({
      url: '/pages/myorder/apply_sale/apply_sale'
    })
  },
  gologistics_info:function(){
    wx.navigateTo({
      url: '/pages/myorder/logistics_info/logistics_info',
    })
  },
  goorder_detail: function (e) {
    let that = that;
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/myorder/order_details/order_details?id='+id
    })
  },
  // 去付款
  goconfirm_order:function(e){
    console.log(e)
    let that = this;
    let id = e.currentTarget.dataset.id;
    let url = app.globalData.URL+'goods/commodity/order/'+id;
        let data = {};
        app.wxRequest('GET', url, data, (res) => {
          console.log(res)
          let commodityId = res.data.orderCommodityList[0].commodityId;
          let count = res.data.orderCommodityList[0].count;
          let modelId = res.data.orderCommodityList[0].modelId;
          let orderCommodityList = [{
            commodityId,count, modelId
          }];
          let data = JSON.stringify({
            addressId: res.data.addressId,
            buyerMessage: res.data.buyerMessage,
            orderCommodityList: orderCommodityList,
            payType: 1,
          });
          let urls = app.globalData.URL + 'goods/commodity/order';
          app.wxRequest('POST', urls, data, (res) => {
            if(res.code!=200){
              wx.showModal({
                title:res.msg
              })
            }else{
              let wxzf = res.data;
                wx.requestPayment({
                  timeStamp:wxzf.timeStamp,
                  nonceStr: wxzf.nonceStr,
                  package: wxzf.package,
                  signType: wxzf.signType,
                  paySign: wxzf.paySign,
                  success (res) {
                    console.log('支付成功')
                  },
                  fail (res) { }
                })
            }
           

          })
          
        }, (err) => {
          console.log(err.errMsg)
        })
  }
})
 